package com.trembear.ucaroauth.service;

import com.trembear.ucaroauth.entity.SysRole;
import com.trembear.ucaroauth.entity.SysUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Junwei.Xiong
 * @description:CustomUserService
 * @create 2018-07-12 9:50
 */
@Service
public class CustomUserService implements UserDetailsService {
    Logger log=LoggerFactory.getLogger(CustomUserService.class);
    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        SysUser user=null;
        log.info(s);
        if(s.equals("admin")){
            log.info(s);
            List<SysRole> list=new ArrayList<>();
            list.add(new SysRole("001","ROLE_BOSS"));
            list.add(new SysRole("002","ROLE_Admin"));
            user=new SysUser("admin","123456", list);
        }
        if(user==null){
            throw new UsernameNotFoundException("用户名不存在");
        }
        log.info(user.getPassword());
        return user;
    }
}
